const Event = (function Event() {
  const clientList = {};

  // 监听事件
  function listen(key, callback) {
    if (clientList[key]) {
      clientList[key].push(callback);
    } else {
      clientList[key] = [callback];
    }
  };

  // 发布事件
  function emit(key, data) {
    console.log(Object.keys(clientList[key]));
    if (clientList[key]) {
      clientList[key].forEach(fn => fn(data));
    }
  }

  // 移除事件
function remove(key) {
  if (clientList[key]) {
    clientList[key] = [];
  }
}

  return {
    listen,
    emit,
    remove,
  };
}());

Event.listen('hi', (data) => {
  console.log(`nice1 to meet ${data}`);
});
Event.listen('hi', (data) => {
  console.log(`nice2 to meet ${data}`);
});

Event.emit('hi', 'liao');
Event.remove('hi');
Event.emit('hi', 'liao');
